<template>
	<view class="content">
		<text>今日总核销：{{count}} 个券码</text>
		<button @click="scanCode">核销券码</button>
	</view>
</template>

<script setup>
	import Base64 from 'base-64';

	import {
		verification,
		evaluateStatistic
	} from '@/api'
	import {
		ref
	} from 'vue';
	const userId = ref()
	const count = ref()
	import {
		onLoad,
	} from '@dcloudio/uni-app'
	onLoad(params => {
		
		userId.value = params.userId
		getCount()
	})
	/** 获取核销数量*/
	const getCount = async()=>{
		const res = await evaluateStatistic({userId:userId.value})
		count.value = res.result
	}
	const scanCode = () => {
		wx.scanCode({
			onlyFromCamera: true,
			async success(res) {
				if (res.errMsg == 'scanCode:ok') {
					const data = await verification({
						codeStr: Base64.encode(res.result),
						userId: userId.value
					})
					getCount()
					uni.showModal({
						title:"提示",
						content:'操作成功'
					})

				} else {
					uni.showToast({
						title: '扫码失败',
						icon: 'none'
					})
				}
			}
		})
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		width: 690rpx;
		margin: 30rpx auto;
		justify-content: space-between;
		align-items: center;

		button {
			width: 220rpx;
			height: 70rpx;
			background: #FE9B23;
			border-radius: 35rpx;
			color: #fff;
			line-height: 70rpx;
			margin: 0;
			padding: 0;
		}

		text {
			font-size: 28rpx;
		}
	}
</style>